package com.xuecheng.content.controller;

import com.xuecheng.api.content.TeachplanControllerApi;
import com.xuecheng.api.content.model.dto.TeachplanDTO;
import com.xuecheng.api.content.model.vo.TeachplanVO;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.content.convert.TeachplanConvert;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author 黄子弟
 */
@Slf4j
@RestController
@RequestMapping("teachplan")
public class TeachplanController implements TeachplanControllerApi {

    @Autowired
    private TeachplanService  teachplanService;


    @Override
    @GetMapping("/{courseBaseId}/tree-nodes")
    public TeachplanDTO getTeachplan(@PathVariable Long courseBaseId) {
        Long companyId = SecurityUtil.getCompanyId();
        TeachplanDTO dto = teachplanService.getTeachplan(courseBaseId, companyId);
        return dto;
    }

    @Override
    @PostMapping
    public TeachplanDTO createOrModifyTeachplan(@RequestBody TeachplanVO vo) {
        TeachplanDTO dto = TeachplanConvert.INSTANCE.vo2dto(vo);
        Long companyId = SecurityUtil.getCompanyId();
        TeachplanDTO teachplanDTO = teachplanService.createOrModifyTeachplan(dto, companyId);
        return teachplanDTO;
    }

    @Override
    @DeleteMapping("/{teachPlanId}")
    public void removeTeachplan(@PathVariable Long teachPlanId) {
        Long companyId = SecurityUtil.getCompanyId();
        teachplanService.removeTeachplan(teachPlanId,companyId);
    }
}
